package com.bitdf.txing.group.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.bitdf.txing.common.enume.TxCodeEnume;
import com.bitdf.txing.common.utils.PageUtils;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.group.entity.GroupRequestAddEntity;
import com.bitdf.txing.group.service.GroupRequestAddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 
 *
 * @author lizhiwei
 * @email 123@qq.com
 * @date 2023-02-04 12:23:05
 */
@RestController
@RequestMapping("${txing.request.path.group}/request")
public class GroupRequestAddController {
    @Autowired
    private GroupRequestAddService groupRequestAddService;

    /**
     * 列表
     */
    @SaCheckLogin
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = groupRequestAddService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @SaCheckLogin
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		GroupRequestAddEntity groupRequestAdd = groupRequestAddService.getById(id);

        return R.ok().put("groupRequestAdd", groupRequestAdd);
    }

    /**
     * 添加 组团请求
     */
    @SaCheckLogin
    @PostMapping("/add")
    public R save(@RequestBody GroupRequestAddEntity groupRequestAdd){
        boolean save = groupRequestAddService.save(groupRequestAdd);
        return R.ok().put("data",groupRequestAdd);
    }

    /**
     * 同意加入组团
     */
    @SaCheckLogin
    @GetMapping("/agree")
    public R agreeGroupRequest(@RequestParam("id") Long id){
        Boolean b = groupRequestAddService.agree(id);
        return b ? R.ok() : R.error(TxCodeEnume.COMMON_OPS_FAILURE_EXCEPTION);
    }

    /**
     * 拒绝加入组团
     */
    @SaCheckLogin
    @GetMapping("/reject")
    public R rejectGroupRequest(@RequestParam("id") Long id){
        Boolean b = groupRequestAddService.reject(id);
        return b ? R.ok() : R.error(TxCodeEnume.COMMON_OPS_FAILURE_EXCEPTION);
    }


    /**
     * 删除
     */
    @SaCheckLogin
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		groupRequestAddService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
